package training.bms.business;

import java.util.Date;

import training.bms.persistence.BlogDAO;
import training.bms.persistence.IBlogDAO;
import training.framework.business.BusinessException;

public class BlogController {

	private IBlogDAO dao;

	public BlogController(IBlogDAO dao){
		this.dao = dao;
	}
	
	public BlogController(){
		this.dao = new BlogDAO();
	}
	
	public void saveBlog(Blog blog) {
		String nome = blog.getName();
		
		Blog db = dao.selectBlog(nome);
		
		if (db == null){
			blog.setDate(new Date());
			dao.insertBlog(blog);
		}else{
			throw new BusinessException("Nome ja existe");
		}
	}

}
